<template>
	<div style="display: inline-block;">
		<view class="bank-license" v-for="item,index in Fimages" :key='index'>
			<block v-if="item">
				<img class="license-pic" :src="item" alt="" />
				<u-icon v-if="!flag" name="close" class='del-icon' size='30' @click.stop="handleRemove(item, index)">
				</u-icon>
			</block>
		</view>
		<view class="bank-license" @click="uploadAva">
			<text>+</text>
		</view>
		<!-- <slot v-show="false" name="cont"><button>上传</button></slot> -->
	</div>
</template>

<script>
	import webUrl from '@/config.js';
	import qiniuUploader from './qiniuUploader.js';
	import {
		getEnToken
	} from '@/access/common.js';
	export default {
		data() {
			return {
				Fimages: []
			};
		},
		props: {
			images: {
				// type: Array,
				default: () => {
					return [];
				}
			},
			flag: {
				type: Boolean,
				default: false
			},
		},
		watch: {
			images(val) {
				this.Fimages = val;
			}
		},
		created() {
			this.Fimages = this.images;
		},
		methods: {
			// 上传头像
			uploadAva() {
				uni.chooseImage({
					success: async res => {
						const filePath = res.tempFilePaths[0]; //选择图片的路径
						uni.showLoading({
							title: '上传中'
						});
						qiniuUploader.upload({
							filePath: filePath,
							success: (res) => {
								uni.hideLoading();
								this.$emit('uploadSuccess', res, res.fullurl);
							},
							fail: (error) => {
								uni.hideLoading();
								uni.showToast({
									title: '上传失败',
									icon: 'none'
								});
								console.error('upload fail:', error)
							}
						});
					}
				});
			},
			//移除图片
			handleRemove(url, index) {
				this.Fimages.splice(index, 1);
				this.$emit('handleRemove', this.Fimages);
			}
		}
	};
</script>

<style scoped lang="scss">
	.bank-license {
		width: 124upx;
		height: 124upx;
		border-radius: 8upx;
		border: 2upx #999999 dashed;
		margin: 32upx 10rpx;
		background: #eee;
		text-align: center;
		line-height: 100upx;
		color: #666;
		font-size: 100rpx;
		font-weight: 300;
		display: inline-block;
		vertical-align: middle;
		position: relative;

		.license-pic {
			width: 120upx;
			height: 120upx;
			display: block;
		}

		.del-icon {
			box-sizing: border-box;
			padding-left: 7rpx;
			position: absolute;
			color: #fff;
			right: -12rpx;
			top: -20upx;
			background-color: #FD463E;
			width: 40rpx;
			height: 40rpx;
			border-radius: 100%;
			line-height: 40rpx;
		}
	}
</style>
